﻿using CapaNegocio;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CapaPresentacion
{
    public partial class frmBuscarProveedorClient : Form
    {

        public static string Variable;
        string frmCancelarCuenta;
        private static frmBuscarProveedorClient _Instancia;
        public static frmBuscarProveedorClient GetInstancia()
        {
            if (_Instancia == null)
            {
                _Instancia = new frmBuscarProveedorClient();
            }
            return _Instancia;
        }

        public void SetPersonaEmp(string id, string cuenta, string nombrecuenta)
        {
            this.txtBusProve.Text = cuenta;
            this.lblruc.Text = nombrecuenta;
        }

        public frmBuscarProveedorClient()
        {
            InitializeComponent();
        }

        private void frmBuscarProveedorClient_Load(object sender, EventArgs e)
        {
          
           
        }

        private void txtBuscarruc_TextChanged(object sender, EventArgs e)
        {

        }
    

        private void txtBuscarruc_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                using (SqlConnection cn = new SqlConnection("Data Source=SISTEMASV\\SQLNEFTA; Initial Catalog=dbventas; Integrated Security=true"))
                {
                    cn.Open();

                    string query = "SELECT * FROM persona_empresa WHERE ruc = @id";
                    SqlCommand cmd = new SqlCommand(query, cn);

                    cmd.Parameters.AddWithValue("@id", Convert.ToInt64(txtBusProve.Text));

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        txtBusProve.Text = reader["ruc"].ToString();
                        lblruc.Text = reader["razon_social"].ToString();
                    }

                }
            }
        }

        private void BtnAceptar_Click(object sender, EventArgs e)
        {
            frmCancelarCuenta form = new frmCancelarCuenta();
            Variable = txtBusProve.Text;
            form.ShowDialog();
            this.Hide();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void frmBuscarProveedorClient_FormClosing(object sender, FormClosingEventArgs e)
        {
            _Instancia = null;
        }



    }
}
